 /*
  * 
  * 话费产出   话费产出总览 
  * 
  */
$(function(){
	loadDatas();
	
	//初始化日期控件
  	$('#bt, #et').datetimepicker({
  		language: 'zh-CN',
	    format: 'yyyy-mm-dd',
	    autoclose: true,
	    minuteStep: 1,
	    minView: "month"
	});
});

//查询所有
function findAll(){
	$("#begin_time, #end_time").val("");
	loadDatas();
}

//查询数据
function loadDatas(){
	//初始化话费产出统计的div
	$("#chanChuCount").html("").css({color: "",height: "300px", lineHeight: ""});
	//加载话费产出统计图
	loadCountCharts();
	//加载话费产出总览数据
	loadHuaFeiOutput();
}

//加载话费产出统计图
function loadCountCharts(){
	var begin = $("#begin_time").val();
	var end = $("#end_time").val();
	$.ajax({
		type:"post",
		data: {"begin": begin, "end": end},
		url:"../../../php/charts/huaFeiOutPut/loadHuaFeiOutPutCountChart.php",
		beforeSend: function(){
			$("#load").css("display","block");
		},
		success: function(msg){
			$("#load").css("display","none");
			var datas = msg.counts;
			
			if(datas.length == 0){
				$("#chanChuCount").html("没查询到符合条件的数据~").css({color: "red",height: "100px", lineHeight: "100px"});
			}else{
				//加载曲线图
				Morris.Area({
				    element: 'chanChuCount',
				    behaveLikeLine: false,
				    gridTextFamily: '微软雅黑',
				    data: datas,
				    xkey: 'x',
				    ykeys: 'y',
				    labels: ['产出值'],
				    lineColors:['#6dc5a3'],
				    smooth: true, //幅度效果
				    hideHover: true, //滑鼠移出图表时，提示框是否隐藏
				    parseTime: false,
				    units: '元',//单位
				    pointColor: '#fff'
				});
			}
		}
	});
}

//加载话费产出总览数据
function loadHuaFeiOutput(){
	$.ajax({
		type:"post",
		url:"../../../php/charts/huaFeiOutPut/loadHuaFeiOutPut.php",
		async:true,
		beforeSend: function(){
			$("#load").css("display","block");
		},
		success: function(msg){
			$("#load").css("display","none");
			$("#today").html(msg.todayHuaFei);
			$("#all").html(msg.allHuaFei);
			loadDataTable(msg.records);
		}
	});
}

//加载话费产出总览数据表格
function loadDataTable(datas){
	$("#tishiTr").remove();
	$('#dataTable').bootstrapTable({
	    columns: [{
	        field: 'serverId',
	        title: 'serverId'
	    }, {
	        field: 'roomName',
	        title: '房间名称'
	    }, {
	        field: 'huaFei',
	        title: '产出话费'
	    }],
	    data: datas,
	    striped: true, //是否显示斑马线
	    detailView: true,//显示详细页面模式
	    detailFormatter: function(index, row){
	    	var serverid = row.serverId;
			getDetail(serverid);
			
			return "<div id='detail_"+serverid+"'></div>";
	    }
	});
}

//根据房间加载话费产出详情
function getDetail(serverid){
	$.ajax({
		type:"post",
		data: {"serverId": serverid},
		url:"../../../php/charts/huaFeiOutPut/loadHuaFeiOutPutDetail.php",
		async:true,
		beforeSend: function(){
			$("#load").css("display","block");
		},
		success: function(msg){
			$("#load").css("display","none");
			var rows = msg.records;
			
			var html = "<table class='table table-bordered table-condensed table-hover'>";
			if(rows.length == 0){
				html += "<tr><td colspan='2'>暂无数据~</td></tr>";
			}else{
				for(var i = 0; i < rows.length; i ++){
					html += "<tr><td>"+rows[i].goodsName+"</td><td>数量："+rows[i].count+"</td></tr>";
				}
			}
			html += "</table>";
			$("#detail_"+serverid).html(html);
		}
	});
}
